home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
353_02
/
virtual5.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-18
|
1KB
|
64 lines
// Chapter 10 - Program 5
#include <iostream.h>
class vehicle {
int wheels;
float weight;
public:
void message(void) { cout << "Vehicle message\n";}
};
class car : public vehicle {
int passenger_load;
public:
void message(void) { cout << "Car message\n";}
};
class truck : public vehicle {
int passenger_load;
float payload;
public:
int passengers(void) {return passenger_load;}
};
class boat : public vehicle {
int passenger_load;
public:
int passengers(void) {return passenger_load;}
void message(void) { cout << "Boat message\n";}
};
main()
{
vehicle *unicycle;
unicycle = new vehicle;
unicycle->message();
delete unicycle;
unicycle = new car;
unicycle->message();
delete unicycle;
unicycle = new truck;
unicycle->message();
delete unicycle;
unicycle = new boat;
unicycle->message();
delete unicycle;
}
// Result of execution
//
// Vehicle message
// Vehicle message
// Vehicle message
// Vehicle message